package foo.bar.wiki.web.action.general;

import foo.bar.wiki.web.action.BaseActionBean;
import foo.bar.wiki.web.action.ExtendedPaginatedList;
import foo.bar.wiki.web.action.PaginatedBaseActionBean;
import foo.bar.wiki.web.nonextension.NullResolution;
import foo.bar.wiki.services.WikiService;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.integration.spring.SpringBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author tmjee
 * @version $Date$ $Id$
 */
public class DashboardActionBean extends PaginatedBaseActionBean {

    private static final Log LOG = LogFactory.getLog(DashboardActionBean.class);

    public static final String VIEW = "/general/dashboard.jsp";

    private WikiService wikiService;


    private ExtendedPaginatedList spaces;
    private ExtendedPaginatedList recentUpdatedPages;
    private ExtendedPaginatedList favouritePages;

    @DefaultHandler
    public Resolution view() {
        return new ForwardResolution(generateThemePath(VIEW));
    }


    public Resolution listSpaces() {
        spaces = getPaginatedList("listSpaces");
        spaces = wikiService.getSpaces(spaces);
        return new NullResolution();            
    }

    public Resolution recentUpdates() {
        recentUpdatedPages = getPaginatedList("recentUpdatedPages");
        recentUpdatedPages = wikiService.getRecentlyUpdatedPages(recentUpdatedPages);
        return new NullResolution();
    }

    public Resolution doFavouritePages() {
        favouritePages = getPaginatedList("favouritePages");
        favouritePages = wikiService.getFavouritePages(getCurrentUser(), favouritePages);
        return new NullResolution();
    }





    @SpringBean("wikiService")
    public void setWikiService(WikiService wikiService) {
        this.wikiService = wikiService;
    }

    public ExtendedPaginatedList getSpaces() {
        return spaces;
    }

    public void setSpaces(ExtendedPaginatedList spaces) {
        this.spaces = spaces;
    }

    public ExtendedPaginatedList getRecentUpdatedPages() {
        return recentUpdatedPages;
    }

    public void setRecentUpdatedPages(ExtendedPaginatedList recentUpdatedPages) {
        this.recentUpdatedPages = recentUpdatedPages;
    }

    public ExtendedPaginatedList getFavouritePages() {
        return favouritePages;
    }

    public void setFavouritePages(ExtendedPaginatedList favouritePages) {
        this.favouritePages = favouritePages;
    }
}
